/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PrestatarioxCliente.java
 *
 * Created on 03-may-2013, 23:08:59
 */
package PrestatarioXCliente;

import javax.swing.table.DefaultTableModel;

/**
 *
 * @author EDGAR
 */
public class PrestatarioxCliente extends javax.swing.JFrame {
DefaultTableModel modeloTabla =new DefaultTableModel();
int Contador;
    /** Creates new form PrestatarioxCliente */
    public PrestatarioxCliente() {
        initComponents();
        TabInnerJoin.setModel(modeloTabla);
        modeloTabla.addColumn("CodPrestatario");
        modeloTabla.addColumn("CodCliente");
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        TabPrestatario = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        TabCliente = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        TabInnerJoin = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        TabPrestatario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"P1", "C3"},
                {"P2", "C1"},
                {"P3", "C2"}
            },
            new String [] {
                "CodPrestatario", "CodCliente"
            }
        ));
        jScrollPane1.setViewportView(TabPrestatario);

        TabCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"C1"},
                {"C2"},
                {"C3"}
            },
            new String [] {
                "CodCliente"
            }
        ));
        jScrollPane2.setViewportView(TabCliente);

        jButton1.setText("|X|");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("La siguiente simulacion consiste en mostrar la operacion |X| entre cliente y Prestatario");

        TabInnerJoin.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"p1", "c3", "c1"},
                {"p2", "c1", "c1"},
                {"p3", "c2", "c1"},
                {"p1", "c3", "c2"},
                {"p2", "c1", "c2"},
                {"p3", "c3", "c2"},
                {"p1", "c3", "c3"},
                {"p2", "c1", "c3"},
                {"p3", "c2", "c3"}
            },
            new String [] {
                "CodPrestatario", "CodCliente", "CodCliente"
            }
        ));
        jScrollPane3.setViewportView(TabInnerJoin);

        jLabel2.setText("Como se puede Observar en la siguiente tabla se hizo un inner join completo");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(132, 132, 132)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(99, 99, 99)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36)
                        .addComponent(jButton1)
                        .addGap(29, 29, 29)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(115, 115, 115)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 474, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(52, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(154, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(133, 133, 133))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))))
                .addGap(36, 36, 36)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addContainerGap(51, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
        Object[] fila=new Object[9];
        String CodCliente;
        String CodPrestatario;
        //for(int i=contador;i< TabPrestatario.getRowCount();i++)
        //{
        if(Contador<TabPrestatario.getRowCount())
        {
            //txtCodPrestatario.setText(TabPrestatario.getValueAt(Contador, 0).toString());
            CodPrestatario=TabPrestatario.getValueAt(Contador, 1).toString();
            for(int j=0;j< TabCliente.getRowCount();j++)
            {
                CodCliente=TabCliente.getValueAt(j, 0).toString();
                if(CodPrestatario==CodCliente)
                {
                    fila[0]=TabPrestatario.getValueAt(Contador, 0).toString();
                    fila[4]=TabCliente.getValueAt(j, 0).toString();
                    fila[5]=TabCliente.getValueAt(j, 1).toString();
                    fila[6]=TabCliente.getValueAt(j, 2).toString();
                    fila[7]=TabCliente.getValueAt(j, 3).toString();
                    fila[8]=TabCliente.getValueAt(j, 4).toString();
                    modeloTabla.addRow(fila);
                }
            }
            Contador++;
        } 
}//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PrestatarioxCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PrestatarioxCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PrestatarioxCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PrestatarioxCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new PrestatarioxCliente().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable TabCliente;
    private javax.swing.JTable TabInnerJoin;
    private javax.swing.JTable TabPrestatario;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    // End of variables declaration//GEN-END:variables
}
